import 'package:flutter/cupertino.dart';
import 'package:flutter_deer/index/iview/indicator_document_list_iview.dart';
import 'package:flutter_deer/index/models/indicator_document_entity.dart';
import 'package:flutter_deer/mvp/base_page_presenter.dart';
import 'package:flutter_deer/net/base_entity.dart';
import 'package:flutter_deer/net/net.dart';
import 'package:flutter_deer/res/constant.dart';

class IndicatorDocumentListPagePresenter
    extends BasePagePresenter<IndicatorDocumentListIMvpView> {
  IndicatorDocumentListPagePresenter();

  @override
  void initState() {}

  Future<dynamic> getIndicatorDocumentList(String? fiscalYear) async {
    WidgetsBinding.instance.addPostFrameCallback((_) {
      final Map<String, dynamic> params = <String, dynamic>{};
      params['fiscal_year'] = fiscalYear;
      params['page_size'] = Constant.pageSize;
      params['current'] = 1;
      asyncRequestNetwork<BaseEntity<IndicatorDocumentPageEntity>>(Method.get,
          url: HttpApi.indicatorDocumentPageList,
          queryParameters: params, onSuccess: (data) {
        view.setIndicatorDocumentPage(data!.data);
      }, onError: (code, msg) {});
    });
  }

  Future<dynamic> getMoreIndentList(String? fiscalYear, int? pageNo) async {
    WidgetsBinding.instance.addPostFrameCallback((_) {
      final Map<String, dynamic> params = <String, dynamic>{};
      params['fiscal_year'] = fiscalYear;
      params['page_size'] = Constant.pageSize;
      params['current'] = pageNo;
      asyncRequestNetwork<BaseEntity<IndicatorDocumentPageEntity>>(Method.get,
          url: HttpApi.indicatorDocumentPageList,
          queryParameters: params, onSuccess: (data) {
        view.setIndicatorDocumentPage(data!.data);
      }, onError: (code, msg) {});
    });
  }
}
